/*
 Given nums = [2, 7, 11, 15], target = 9,

 Because nums[0] + nums[1] = 2 + 7 = 9,
 return [0, 1].
 */


/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
let twoSum = function(nums, target) {
    let map = {};
    for(let i = 0; i < nums.length; i++){
        map[nums[i]] = i;
    }

    for(let i = 0; i < nums.length; i++){
        let index = map[target - nums[i]];
        if(index != null&&index != i){
            return [i, index];
        }
    }
    return null;
};




console.log(twoSum([3,2,4], 6));